clear all
version 15

****************************************************************************************************
* -----   Customize the paths and options:   ----- 
****************************************************************************************************
global MY_IN_PATH   "C:\replication\data\raw\"
global MY_OUT_PATH  "C:\replication\data\work\"
****************************************************************************************************

cd "${MY_IN_PATH}"

* prepare shapefiles
shp2dta using s_11au16.shp, database(usdb) coordinates(uscoord) genid(id)
use uscoord.dta, clear
drop if _ID == 1 // Alaska
drop if _ID == 4 // American Samoa
drop if _ID == 13 // Hawaii
drop if _ID == 39 // Puerto Rico
drop if _ID == 46 // Virgin Islands
drop if _ID == 54 // Guam
drop if _ID == 55 // Northern Marianas
save USmap.dta, replace

* geo data
use "${MY_OUT_PATH}geo_cited_citing.dta", clear
keep cited inventor_id_cited* lat_cited* lng_cited*
duplicates drop
reshape long inventor_id_cited lat_cited lng_cited, i(cited) j(seq_id)
drop if inventor_id_cited == ""
gen deceased = 0
replace deceased = 1 if seq_id == 1
sum lat lng if deceased == 1
sum lat lng if deceased == 0

* map
append using "${MY_IN_PATH}USmap.dta"
line _Y _X, cmiss(n) || sc lat lng if deceased == 1 & lng > -130, msymbol(x) mcolor(red) subtitle("Deceased Inventors") leg(off) xla(-124/-71) yla(,nogrid) ysc(off) xsc(off) graphr(fc(white))
line _Y _X, cmiss(n) || sc lat lng if deceased == 0 & lng > -130, msymbol(x) mcolor(blue) subtitle("Co-Inventors") leg(off) xla(-124/-71) yla(,nogrid) ysc(off) xsc(off) graphr(fc(white))

exit
